package com.tao.content.api;

import com.tao.base.model.PageResult;
import com.tao.base.model.Result;
import com.tao.content.domain.dto.AddCourseDto;
import com.tao.content.domain.dto.SelectCourseDto;
import com.tao.content.domain.dto.UpdateCourseDto;
import com.tao.content.domain.pojo.CourseBase;
import com.tao.content.domain.vo.CourseBaseInfoVo;
import com.tao.content.domain.vo.CourseVo;
import com.tao.content.service.impl.CourseBaseServiceImpl;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/course")
@Tag(name = "课程基本信息接口",description = "管理课程基本信息")
@RequiredArgsConstructor
public class CourseBaseInfoController {
    final CourseBaseServiceImpl courseBaseService;
    @PostMapping("/list")
    @Operation(summary = "查询课程",description = "根据特定条件分页查询")
    @Parameters(value = {
            @Parameter(name = "page", description = "页数", in = ParameterIn.QUERY),
            @Parameter(name = "pageSize", description = "每页大小", in = ParameterIn.QUERY)
    })
    @PreAuthorize("hasAuthority('teachmanager_course_list')")
    public Result<PageResult<CourseVo>> list(@RequestBody SelectCourseDto selectCourseDto, @RequestParam("page") Long page, @RequestParam("pageSize") Long pageSize){
        selectCourseDto.setPageNo(page);
        selectCourseDto.setPageSize(pageSize);
        return Result.success(courseBaseService.coursePage(selectCourseDto));
    }

    @PostMapping("")
    @Operation(summary = "添加课程",description = "添加课程基本信息和营销信息")
    public Result<CourseBaseInfoVo> addCourse(@RequestBody @Validated AddCourseDto addCourseDto){
        return Result.success(courseBaseService.addCourse(addCourseDto,1232141425L));
    }

    @GetMapping("/{id}")
    @PreAuthorize("hasAuthority('sysmanager_menu_add')")
    @Operation(summary = "根据id查询课程")
    @Parameter(name = "id",description = "查询的课程id",in = ParameterIn.PATH)
    public Result<CourseBaseInfoVo> getCourse(@PathVariable Long id){
        return Result.success(courseBaseService.getCourse(id));
    }

    @PutMapping("")
    @Operation(summary = "修改课程",description = "修改课程基本信息和营销信息")
    public Result<CourseBaseInfoVo> saveCourse(@RequestBody UpdateCourseDto updateCourseDto){
        return Result.success(courseBaseService.updateCourse(updateCourseDto,1232141425L));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除课程",description = "删除课程基本信息以及相联的媒资信息,教师信息等")
    @Parameter(name = "id",description = "删除的课程id",in = ParameterIn.PATH)
    public Result removeCourse(@PathVariable("id") Long id){
        courseBaseService.removeCourse(id);
        return Result.success();
    }
}
